﻿using System;

namespace UniRx.Operators
{
	// Token: 0x02000272 RID: 626
	internal class CombineLatestObservable<T1, T2, T3, T4, T5, T6, T7, TR> : OperatorObservableBase<TR>
	{
		// Token: 0x06000E28 RID: 3624 RVA: 0x00042DA8 File Offset: 0x000411A8
		public CombineLatestObservable(IObservable<T1> source1, IObservable<T2> source2, IObservable<T3> source3, IObservable<T4> source4, IObservable<T5> source5, IObservable<T6> source6, IObservable<T7> source7, CombineLatestFunc<T1, T2, T3, T4, T5, T6, T7, TR> resultSelector) : base(source1.IsRequiredSubscribeOnCurrentThread<T1>() || source2.IsRequiredSubscribeOnCurrentThread<T2>() || source3.IsRequiredSubscribeOnCurrentThread<T3>() || source4.IsRequiredSubscribeOnCurrentThread<T4>() || source5.IsRequiredSubscribeOnCurrentThread<T5>() || source6.IsRequiredSubscribeOnCurrentThread<T6>() || source7.IsRequiredSubscribeOnCurrentThread<T7>())
		{
			this.source1 = source1;
			this.source2 = source2;
			this.source3 = source3;
			this.source4 = source4;
			this.source5 = source5;
			this.source6 = source6;
			this.source7 = source7;
			this.resultSelector = resultSelector;
		}

		// Token: 0x06000E29 RID: 3625 RVA: 0x00042E4D File Offset: 0x0004124D
		protected override IDisposable SubscribeCore(IObserver<TR> observer, IDisposable cancel)
		{
			return new CombineLatestObservable<T1, T2, T3, T4, T5, T6, T7, TR>.CombineLatest(7, this, observer, cancel).Run();
		}

		// Token: 0x04000823 RID: 2083
		private IObservable<T1> source1;

		// Token: 0x04000824 RID: 2084
		private IObservable<T2> source2;

		// Token: 0x04000825 RID: 2085
		private IObservable<T3> source3;

		// Token: 0x04000826 RID: 2086
		private IObservable<T4> source4;

		// Token: 0x04000827 RID: 2087
		private IObservable<T5> source5;

		// Token: 0x04000828 RID: 2088
		private IObservable<T6> source6;

		// Token: 0x04000829 RID: 2089
		private IObservable<T7> source7;

		// Token: 0x0400082A RID: 2090
		private CombineLatestFunc<T1, T2, T3, T4, T5, T6, T7, TR> resultSelector;

		// Token: 0x02000273 RID: 627
		private class CombineLatest : NthCombineLatestObserverBase<TR>
		{
			// Token: 0x06000E2A RID: 3626 RVA: 0x00042E5D File Offset: 0x0004125D
			public CombineLatest(int length, CombineLatestObservable<T1, T2, T3, T4, T5, T6, T7, TR> parent, IObserver<TR> observer, IDisposable cancel) : base(length, observer, cancel)
			{
				this.parent = parent;
			}

			// Token: 0x06000E2B RID: 3627 RVA: 0x00042E7C File Offset: 0x0004127C
			public IDisposable Run()
			{
				this.c1 = new CombineLatestObserver<T1>(this.gate, this, 0);
				this.c2 = new CombineLatestObserver<T2>(this.gate, this, 1);
				this.c3 = new CombineLatestObserver<T3>(this.gate, this, 2);
				this.c4 = new CombineLatestObserver<T4>(this.gate, this, 3);
				this.c5 = new CombineLatestObserver<T5>(this.gate, this, 4);
				this.c6 = new CombineLatestObserver<T6>(this.gate, this, 5);
				this.c7 = new CombineLatestObserver<T7>(this.gate, this, 6);
				IDisposable disposable = this.parent.source1.Subscribe(this.c1);
				IDisposable disposable2 = this.parent.source2.Subscribe(this.c2);
				IDisposable disposable3 = this.parent.source3.Subscribe(this.c3);
				IDisposable disposable4 = this.parent.source4.Subscribe(this.c4);
				IDisposable disposable5 = this.parent.source5.Subscribe(this.c5);
				IDisposable disposable6 = this.parent.source6.Subscribe(this.c6);
				IDisposable disposable7 = this.parent.source7.Subscribe(this.c7);
				return StableCompositeDisposable.Create(new IDisposable[]
				{
					disposable,
					disposable2,
					disposable3,
					disposable4,
					disposable5,
					disposable6,
					disposable7
				});
			}

			// Token: 0x06000E2C RID: 3628 RVA: 0x00042FDC File Offset: 0x000413DC
			public override TR GetResult()
			{
				return this.parent.resultSelector(this.c1.Value, this.c2.Value, this.c3.Value, this.c4.Value, this.c5.Value, this.c6.Value, this.c7.Value);
			}

			// Token: 0x06000E2D RID: 3629 RVA: 0x00043046 File Offset: 0x00041446
			public override void OnNext(TR value)
			{
				this.observer.OnNext(value);
			}

			// Token: 0x06000E2E RID: 3630 RVA: 0x00043058 File Offset: 0x00041458
			public override void OnError(Exception error)
			{
				try
				{
					this.observer.OnError(error);
				}
				finally
				{
					base.Dispose();
				}
			}

			// Token: 0x06000E2F RID: 3631 RVA: 0x00043090 File Offset: 0x00041490
			public override void OnCompleted()
			{
				try
				{
					this.observer.OnCompleted();
				}
				finally
				{
					base.Dispose();
				}
			}

			// Token: 0x0400082B RID: 2091
			private readonly CombineLatestObservable<T1, T2, T3, T4, T5, T6, T7, TR> parent;

			// Token: 0x0400082C RID: 2092
			private readonly object gate = new object();

			// Token: 0x0400082D RID: 2093
			private CombineLatestObserver<T1> c1;

			// Token: 0x0400082E RID: 2094
			private CombineLatestObserver<T2> c2;

			// Token: 0x0400082F RID: 2095
			private CombineLatestObserver<T3> c3;

			// Token: 0x04000830 RID: 2096
			private CombineLatestObserver<T4> c4;

			// Token: 0x04000831 RID: 2097
			private CombineLatestObserver<T5> c5;

			// Token: 0x04000832 RID: 2098
			private CombineLatestObserver<T6> c6;

			// Token: 0x04000833 RID: 2099
			private CombineLatestObserver<T7> c7;
		}
	}
}
